<?php
namespace Home\Controller;
use Think\Controller;
class ManageController extends Controller {
	 public function _initialize(){
	   if(session("username")){
		
			
		}else{
			  $this->redirect("Login/index"); 
		}
		$this->assign('index',6);
   }
    public function index(){
		
		 $managedao=M('manage');
		
		 $where="";
		
		 $count =$managedao->where($where)->count();
		 $Page= new \Think\Page($count,10);
		 
		 $show= $Page->show();// 分页显示输出
		 
		 $list=$managedao->where($where)->order('id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
		 
		 $this->assign('alist',$list);
		 $this->assign('page',$show);
	
		layout('Layout/layout');
		$this->display();
      
    }
	
	public function add(){
			 $managedao=M('manage');
		if(IS_POST){
				$data["id"]=$_POST["id"];
				$data["username"]=$_POST["username"];
				$data["password"]=$_POST["password"];
				$data["truename"]=$_POST["truename"];
				$data["createtime"]=time();
				$data["status"]="0";
				if($_POST["id"]){
					
					
				  if($managedao->save($data)){
					   $this->success('修改成功','/index.php/Home/Manage/index');
				  }else{
					   $this->success('修改失败');
				  }
				}else{
					
					
				  if($managedao->add($data)){
					   $this->success('添加成功','/index.php/Home/Manage/index');
				  }else{
					   $this->success('添加失败');
				  }
				}
				
			
				
			
			
		}else{
			if($_GET["id"]){
				$info =$managedao->where("id=".$_GET["id"])->find();
				$this->assign('info',$info);
			}
		
		layout('Layout/layout');
		$this->display();
	}
		}
		
	
	public function del(){
		
		$ids =$_POST["ids"];
		 $model = D("manage");//获取当期模块的操作对象
		 if(strpos($ids,",")){
			$where = 'id in('.$ids.')';
		  }else{
			$where = 'id='.$ids;
		  }
		   $list=$model->where($where)->delete();
		   if($list!==false) {
			  echo "0";
		   }else{
			  echo "-1";
		   }
	}
	
	
	


}